/*
 * Copyright 2006-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.martinimix.domain.account;

import java.io.Serializable;

/**
 * Provides an address bean.
 * 
 * @author Scott Rossillo
 *
 */
public class Address implements Serializable, Cloneable {
	
	private static final long serialVersionUID = 1L;
	
	public final static String STATUS_ENABLED = "ENB";
	public final static String STATUS_DISABLED = "DSB";
	
	public final static String TYPE_BILLING = "BIL";
	public final static String TYPE_SHIPPING = "SHP";
	public final static String TYPE_BOTH = "BTH";
	
	/**
	 * @@BusinessObjectProperty("uad_id")
	 */
	private Long id;
	
	/**
	 * @@BusinessObjectProperty("uad_usa_id")
	 */
	private Long customerId;
	
	/**
	 * @@BusinessObjectProperty("status_cd")
	 */
	private String statusCode;
	
	/**
	 * @@BusinessObjectProperty("type_cd")
	 */
	private String typeCode;
	
	private String label;
	
	private String firstName;
	private String lastName;
	private String address1;
	private String address2;
	private String address3;
	private String city;
	
	/**
	 * @@BusinessObjectProperty("AddressConfirmed", attribute=true) 
	 */
	private boolean confirmed;
	
	/**
	 * @@BusinessObjectProperty("state_cd")
	 */
	private String stateCode;
	
	private String stateName;
	
	/**
	 * @@BusinessObjectProperty("country_cd")
	 */
	private String country;
	
	/**
	 * @@BusinessObjectProperty("phone")
	 */
	private PhoneNumber phoneNumber = new PhoneNumber();
	
	/**
	 * @@BusinessObjectProperty("postal")
	 */
	private String postalCode;
	
	private boolean defaultAddress;
	
	/**
	 * Creates a new address
	 */
	public Address() {
		
		this.statusCode = STATUS_ENABLED;
		this.typeCode = TYPE_BOTH;
		this.defaultAddress = false;
	}
	
	/**
	 * Creates a new address as a copy of the given other address
	 * 
	 * @param other the <code>Address</code> to copy
	 */
	public Address(final Address other) {
		
		this();
		this.address1 = other.address1;
		this.address2 = other.address2;
		this.address3 = other.address3;
		this.city = other.city;
		this.confirmed = other.confirmed;
		this.country = other.country;
		this.customerId = other.customerId;
		this.defaultAddress = other.defaultAddress;
		this.firstName = other.firstName;
		this.label = other.label;
		this.lastName = other.lastName;
		this.phoneNumber = new PhoneNumber(other.phoneNumber);
		this.postalCode = other.postalCode;
		this.stateCode = other.stateCode;
		this.stateName = other.stateName;
		this.statusCode = other.statusCode;
		this.typeCode = other.typeCode;
		
	}
	
	/**
	 * Returns a copy of this address.
	 * 
	 * @return a copy of this <code>Address</code>
	 * 
	 * @see #clone()
	 */
	public Address copy() {
		
		try {
			return (Address) this.clone();
		} catch (CloneNotSupportedException e) {
			// can't happen, we implemented cloneable
			return null;
		}
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#clone()
	 */
	public Object clone() throws CloneNotSupportedException {
		
		return super.clone();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getCustomerId() {
		return customerId;
	}

	public void setCustomerId(Long customerId) {
		this.customerId = customerId;
	}
	
	/**
	 * Returns true if this is address is confirmed.
	 * 
	 * @return <code>true</code> if this <code>Address</code> is
	 * confirmed; <code>false</code> otherwise
	 */
	public boolean isConfirmed() {
		return confirmed;
	}

	/**
	 * Sets the confirmed status of this account.
	 * 
	 * @param confirmed <code>true</code> if this <code>Address</code> is
	 * confirmed; <code>false</code> otherwise
	 */
	public void setConfirmed(boolean confirmed) {
		this.confirmed = confirmed;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getAddress1() {
		return address1;
	}

	public void setAddress1(String address1) {
		this.address1 = address1;
	}

	public String getAddress2() {
		return address2;
	}

	public void setAddress2(String address2) {
		this.address2 = address2;
	}

	public String getAddress3() {
		return address3;
	}

	public void setAddress3(String address3) {
		this.address3 = address3;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getStateCode() {
		return stateCode;
	}

	public void setStateCode(String stateCode) {
		this.stateCode = stateCode;
	}

	public String getStateName() {
		return stateName;
	}

	public void setStateName(String stateName) {
		this.stateName = stateName;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public PhoneNumber getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(PhoneNumber phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public String getPostalCode() {
		return postalCode;
	}

	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}

	public String getStatusCode() {
		return statusCode;
	}

	public void setStatusCode(String statusCode) {
		this.statusCode = statusCode;
	}

	public String getTypeCode() {
		return typeCode;
	}

	public void setTypeCode(String typeCode) {
		this.typeCode = typeCode;
	}
	
	public boolean isDefaultAddress() {
		return defaultAddress;
	}

	public void setDefaultAddress(boolean defaultAddress) {
		this.defaultAddress = defaultAddress;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		
		StringBuffer buf = new StringBuffer(1024);
		
		buf.append("Address[");
		
		buf.append("id=").append(id).append(", ");
		buf.append("customerId=").append(customerId).append(", ");
		
		buf.append("firstName=").append(firstName).append(", ");
		buf.append("lastName=").append(lastName).append(", ");
		
		buf.append("address1=").append(address1).append(", ");
		buf.append("address2=").append(address2).append(", ");
		buf.append("address3=").append(address3).append(", ");
		
		buf.append("city=").append(city).append(", ");
		buf.append("stateCode=").append(stateCode).append(", ");
		buf.append("postalCode=").append(postalCode).append(", ");
		buf.append("country=").append(country).append(", ");
		
		buf.append(']');
		
		return buf.toString();
	}

}
